package com.blame.chatRobot.repository;

import com.blame.chatRobot.entity.ChatInfo;
import org.springframework.stereotype.Repository;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 何彦声
 * Date: 2025-08-30
 * Time:
 */

@Repository
public class MemoryChatHistoryRepository implements ChatHistoryRepository{

//    用LinkedHashMap<>是因为是有序的
    private Map<String,String> chatInfos=new LinkedHashMap<>();


    @Override
    public void save(String title, String chatId) {
        chatInfos.put(chatId, title);
    }

    @Override
    public List<ChatInfo> getChats() {
        return chatInfos.entrySet().stream()
                .map(entry->new ChatInfo(entry.getKey(), entry.getValue()))
                .collect(Collectors.toList());
    }

    @Override
    public void clearByChatId(String chatId) {
        chatInfos.remove(chatId);
    }
}
